var path = $('body').attr('ctxPath');
$(function(){
	$("#project-num").val(0);
	$("#plan-num").val(0);
	$("#materiel-num").val(0);
	getProjectInfo();
});

function nulltoString(data){
	if(data==null){
		data="";
	}
	return data;
}

//获取项目信息
//首次加载
function getProjectInfo(){
	$("#project-num").val(0);
	$.post(path+'/report/project/info/0?t='+new Date().getTime(),function(data){
		if(data.state){
			   //清除元素 保证页面显示正确
			   $('#porject-panel-group').empty();
			   var html = [];
			   var projectList=data.list;
			   if(projectList!=null){
				//控制分页
				if(projectList.length>=5){
					$(".porject-pager .next").removeClass("disabled");
				}
				for(var i = 0; i < projectList.length; i++){
					if(projectList[i].started==0){
						html.push("<div class='panel panel-default'><div class='panel-heading' id='heading-"+projectList[i].id+"'><h4 class='panel-title' ><a  class='text-font-one collapsed' data-toggle='collapse' data-parent='#porject-panel-group' href='#projectInfo-"+projectList[i].id+"'>项目编码&nbsp;:&nbsp;"+projectList[i].projectCode+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称&nbsp;:&nbsp;"+projectList[i].projectName+"</a><span class='pull-right' style='color: #067715;'><i class='icon icon-play'></i>已启动</span></h4></div>" +
						"<div id='projectInfo-"+projectList[i].id+"' class='panel-collapse collapse'><div class='panel-body'><div class='row panl-margin'><span class='col-xs-6'>项目简介&nbsp;:&nbsp;"+projectList[i].projectDesc+"</span><span class='col-xs-3'>项目创建人&nbsp;:&nbsp;"+projectList[i].creatorName+"</span><span class='col-xs-3'>创建时间&nbsp;:&nbsp;"+projectList[i].createDateStr+"</span></div><div class='row panl-margin'><span class='col-xs-6'>项目成员&nbsp;:&nbsp;"+projectList[i].memberName+"</span><span class='col-xs-6'>项目管理员&nbsp;:&nbsp;"+projectList[i].managerName+"</span></div><hr>" +
								"<div class='plans-panel' class='row'><div class='col-xs-2'><ul class='nav nav-tabs nav-stacked'><i class='icon icon-spin icon-spinner-indicator'></i></ul></div><div class='tab-content col-xs-10'></div></div></div></div></div>");
					}else{
						html.push("<div class='panel panel-default'><div class='panel-heading' id='heading-"+projectList[i].id+"'><h4 class='panel-title' ><a  class='text-font-one collapsed' data-toggle='collapse' data-parent='#porject-panel-group' href='#projectInfo-"+projectList[i].id+"'>项目编码&nbsp;:&nbsp;"+projectList[i].projectCode+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称&nbsp;:&nbsp;"+projectList[i].projectName+"</a><span class='pull-right' style='color: #efea1e;'><i class='icon icon-time'></i>未启动</span></h4></div>" +
						"<div id='projectInfo-"+projectList[i].id+"' class='panel-collapse collapse'><div class='panel-body'><div class='row panl-margin'><span class='col-xs-6'>项目简介&nbsp;:&nbsp;"+projectList[i].projectDesc+"</span><span class='col-xs-3'>项目创建人&nbsp;:&nbsp;"+projectList[i].creatorName+"</span><span class='col-xs-3'>创建时间&nbsp;:&nbsp;"+projectList[i].createDateStr+"</span></div><div class='row panl-margin'><span class='col-xs-6'>项目成员&nbsp;:&nbsp;"+projectList[i].memberName+"</span><span class='col-xs-6'>项目管理员&nbsp;:&nbsp;"+projectList[i].managerName+"</span></div><hr>" +
								"<div class='plans-panel' class='row'><div class='col-xs-2'><ul class='nav nav-tabs nav-stacked'><i class='icon icon-spin icon-spinner-indicator'></i></ul></div><div class='tab-content col-xs-10'></div></div></div></div></div>");
					}
				}
				$('#porject-panel-group').append(html.join(' '));
                //点击列表的第一个
                $("#porject-panel-group>.panel-default a:first").click();
		       }else{
		    	    $('#porjects-panel-body').empty();
					$('#porjects-panel-body').append("<div class='col-xs-12'>暂无数据</div>");
				}
			  }else{
				  layer.alert(data.msg);
			  }
	}).error(function(){
		 layer.alert("网络异常,请刷新页面再试");
	});
}
//分页加载更多
//上一页
$('.porject-pager').on('click','.previous', function() {
	//控制分页
	if($(".porject-pager .next").hasClass("disabled")){
		$(".porject-pager .next").removeClass("disabled");
	}
	//加载显示
	$('#porject-panel-group').empty();
	$('#porject-panel-group').append("<i class='icon icon-spin icon-spinner-indicator'></i>");
	var numberOld=$("#project-num").val();
	var number=Number(numberOld)-Number(5);
	$.post(path+'/report/project/info/'+number+'?t='+new Date().getTime(),function(data){
		if(data.state){
		   	//控制分页
		   	if(number<=0){
		   		if(!$(".porject-pager .previous").hasClass("disabled")){
		   			$(".porject-pager .previous").addClass("disabled");
		   		}
		   	}
			   $("#project-num").val(number);
			   //清除元素 保证页面显示正确
			   $('#porject-panel-group').empty();
			   var html = [];
			   var projectList=data.list;
			   if(projectList!=null){
				//控制分页
				if(projectList.length<5){
					if(!$(".porject-pager .next").hasClass("disabled")){
						$(".porject-pager .next").addClass("disabled");
					}
					if(!$(".porject-pager .previous").hasClass("disabled")){
						$(".porject-pager .previous").addClass("disabled");
					}
				}
				for(var i = 0; i < projectList.length; i++){
					if(projectList[i].started==0){
						html.push("<div class='panel panel-default'><div class='panel-heading' id='heading-"+projectList[i].id+"'><h4 class='panel-title' ><a  class='text-font-one collapsed' data-toggle='collapse' data-parent='#porject-panel-group' href='#projectInfo-"+projectList[i].id+"'>项目编码&nbsp;:&nbsp;"+projectList[i].projectCode+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称&nbsp;:&nbsp;"+projectList[i].projectName+"</a><span class='pull-right' style='color: #38b03f;'><i class='icon icon-play'></i>已启动</span></h4></div>" +
						"<div id='projectInfo-"+projectList[i].id+"' class='panel-collapse collapse'><div class='panel-body'><div class='row panl-margin'><span class='col-xs-6'>项目简介&nbsp;:&nbsp;"+projectList[i].projectDesc+"</span><span class='col-xs-3'>项目创建人&nbsp;:&nbsp;"+projectList[i].creatorName+"</span><span class='col-xs-3'>创建时间&nbsp;:&nbsp;"+projectList[i].createDateStr+"</span></div><div class='row panl-margin'><span class='col-xs-6'>项目成员&nbsp;:&nbsp;"+projectList[i].memberName+"</span><span class='col-xs-6'>项目管理员&nbsp;:&nbsp;"+projectList[i].managerName+"</span></div><hr>" +
								"<div class='plans-panel' class='row'><div class='col-xs-2'><ul class='nav nav-tabs nav-stacked'><i class='icon icon-spin icon-spinner-indicator'></i></ul></div><div class='tab-content col-xs-10'></div></div></div></div></div>");
					}else{
						html.push("<div class='panel panel-default'><div class='panel-heading' id='heading-"+projectList[i].id+"'><h4 class='panel-title' ><a  class='text-font-one collapsed' data-toggle='collapse' data-parent='#porject-panel-group' href='#projectInfo-"+projectList[i].id+"'>项目编码&nbsp;:&nbsp;"+projectList[i].projectCode+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称&nbsp;:&nbsp;"+projectList[i].projectName+"</a><span class='pull-right' style='color: #f1a325;'><i class='icon icon-time'></i>未启动</span></h4></div>" +
						"<div id='projectInfo-"+projectList[i].id+"' class='panel-collapse collapse'><div class='panel-body'><div class='row panl-margin'><span class='col-xs-6'>项目简介&nbsp;:&nbsp;"+projectList[i].projectDesc+"</span><span class='col-xs-3'>项目创建人&nbsp;:&nbsp;"+projectList[i].creatorName+"</span><span class='col-xs-3'>创建时间&nbsp;:&nbsp;"+projectList[i].createDateStr+"</span></div><div class='row panl-margin'><span class='col-xs-6'>项目成员&nbsp;:&nbsp;"+projectList[i].memberName+"</span><span class='col-xs-6'>项目管理员&nbsp;:&nbsp;"+projectList[i].managerName+"</span></div><hr>" +
								"<div class='plans-panel' class='row'><div class='col-xs-2'><ul class='nav nav-tabs nav-stacked'><i class='icon icon-spin icon-spinner-indicator'></i></ul></div><div class='tab-content col-xs-10'></div></div></div></div></div>");
					}
				}
				$('#porject-panel-group').append(html.join(' '));
				//点击列表的第一个
                $("#porject-panel-group>.panel-default a:first").click();
		       }else{
		    	    $('#porjects-panel-body').empty();
					$('#porjects-panel-body').append("<div class='col-xs-12'>数据错误,请刷新页面后再试!</div>");
				}
			  }else{
				  layer.alert(data.msg);
			  }
	}).error(function(){
		 layer.alert("网络异常,请刷新页面再试");
	});

});
//下一页
$('.porject-pager').on('click','.next', function() {
	//控制分页
	if($(".porject-pager .previous").hasClass("disabled")){
		$(".porject-pager .previous").removeClass("disabled");
	}
	//加载显示
	$('#porject-panel-group').empty();
	$('#porject-panel-group').append("<i class='icon icon-spin icon-spinner-indicator'></i>");
	var numberOld=$("#project-num").val();
	var number=Number(numberOld)+Number(5);
	$.post(path+'/report/project/info/'+number+'?t='+new Date().getTime(),function(data){
		if(data.state){
			   //控制分页
			   $("#project-num").val(number);
			   //清除元素 保证页面显示正确
			   $('#porject-panel-group').empty();
			   var html = [];
			   var projectList=data.list;
			   if(projectList!=null){
				//控制分页
				if(projectList.length<5){
					if(!$(".porject-pager .next").hasClass("disabled")){
						$(".porject-pager .next").addClass("disabled");
					}
				}
				for(var i = 0; i < projectList.length; i++){
					if(projectList[i].started==0){
						html.push("<div class='panel panel-default'><div class='panel-heading' id='heading-"+projectList[i].id+"'><h4 class='panel-title' ><a  class='text-font-one collapsed' data-toggle='collapse' data-parent='#porject-panel-group' href='#projectInfo-"+projectList[i].id+"'>项目编码&nbsp;:&nbsp;"+projectList[i].projectCode+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称&nbsp;:&nbsp;"+projectList[i].projectName+"</a><span class='pull-right' style='color: #38b03f;'><i class='icon icon-play'></i>已启动</span></h4></div>" +
						"<div id='projectInfo-"+projectList[i].id+"' class='panel-collapse collapse'><div class='panel-body'><div class='row panl-margin'><span class='col-xs-6'>项目简介&nbsp;:&nbsp;"+projectList[i].projectDesc+"</span><span class='col-xs-3'>项目创建人&nbsp;:&nbsp;"+projectList[i].creatorName+"</span><span class='col-xs-3'>创建时间&nbsp;:&nbsp;"+projectList[i].createDateStr+"</span></div><div class='row panl-margin'><span class='col-xs-6'>项目成员&nbsp;:&nbsp;"+projectList[i].memberName+"</span><span class='col-xs-6'>项目管理员&nbsp;:&nbsp;"+projectList[i].managerName+"</span></div><hr>" +
								"<div class='plans-panel' class='row'><div class='col-xs-2'><ul class='nav nav-tabs nav-stacked'><i class='icon icon-spin icon-spinner-indicator'></i></ul></div><div class='tab-content col-xs-10'></div></div></div></div></div>");
					}else{
						html.push("<div class='panel panel-default'><div class='panel-heading' id='heading-"+projectList[i].id+"'><h4 class='panel-title' ><a  class='text-font-one collapsed' data-toggle='collapse' data-parent='#porject-panel-group' href='#projectInfo-"+projectList[i].id+"'>项目编码&nbsp;:&nbsp;"+projectList[i].projectCode+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目名称&nbsp;:&nbsp;"+projectList[i].projectName+"</a><span class='pull-right' style='color: #f1a325;'><i class='icon icon-time'></i>未启动</span></h4></div>" +
						"<div id='projectInfo-"+projectList[i].id+"' class='panel-collapse collapse'><div class='panel-body'><div class='row panl-margin'><span class='col-xs-6'>项目简介&nbsp;:&nbsp;"+projectList[i].projectDesc+"</span><span class='col-xs-3'>项目创建人&nbsp;:&nbsp;"+projectList[i].creatorName+"</span><span class='col-xs-3'>创建时间&nbsp;:&nbsp;"+projectList[i].createDateStr+"</span></div><div class='row panl-margin'><span class='col-xs-6'>项目成员&nbsp;:&nbsp;"+projectList[i].memberName+"</span><span class='col-xs-6'>项目管理员&nbsp;:&nbsp;"+projectList[i].managerName+"</span></div><hr>" +
								"<div class='plans-panel' class='row'><div class='col-xs-2'><ul class='nav nav-tabs nav-stacked'><i class='icon icon-spin icon-spinner-indicator'></i></ul></div><div class='tab-content col-xs-10'></div></div></div></div></div>");
					}
				}
				$('#porject-panel-group').append(html.join(' '));
				//点击列表的第一个
                $("#porject-panel-group>.panel-default a:first").click();
		       }else{
		    	    $('#porject-panel-group').empty();
					$('#porject-panel-group').append("<div class='col-xs-12'>暂无更多数据</div>");
				}
			  }else{
				  layer.alert(data.msg);
			  }
	}).error(function(){
		 layer.alert("网络异常,请刷新页面再试");
	});
});
//加载计划
//首次加载计划标题信息
$('section').on('shown.zui.collapse',"div[id^='projectInfo-']", function () {
	   $("#plan-num").val(0);
	   $("#materiel-num").val(0);
	   var projectId=$(this).attr("id").substr(12);
       var planTitlePanel=$(this).find(".plans-panel>.col-xs-2>ul");
       var planInfoPanel=$(this).find(".plans-panel>.col-xs-10.tab-content");
       $.post(path+'/report/project/plan/title/0?t='+new Date().getTime(),{"projectId":projectId},function(data){
    	   if(data.state){
			   //清除元素 保证页面显示正确
    		   planTitlePanel.empty();
    		   planInfoPanel.empty();
    		   var htmlTitle = [];
    		   var htmlInfo = [];
			   var planList=data.list;
			   if(planList!==null){
					for(var i = 0; i < planList.length; i++){
						htmlTitle.push("<li class='text-font-two'><a href='javascript:void(0);' data-target='#plan-"+planList[i].id+"' data-toggle='tab'>计划编码&nbsp;:&nbsp;"+planList[i].planCode+"</a></li>");
						htmlInfo.push("<div class='tab-pane fade' id='plan-"+planList[i].id+"'><div class='panel plan-item'><div class='panel-body'></div></div>" +
								"<div class='panel table-responsive  scrollbar-hover table-scroll'><table class='table table-condensed'><tr class='th_data' ><th>物料编码</th><th>物料名称</th><th>长(cm)</th><th>宽(cm)</th><th>高(cm)</th><th>体积(m³)</th><th>净重(kg)</th><th>所在容器</th><th width='22%' >所在地点</th></tr></table></div></div>");
					}
				   //控制分页显示
				   if(planList.length>=13){
					   htmlTitle.push("<li><ul class='pager plan-pager pager-justify pager-pills col-xs-12'><li class='previous col-xs-9 disabled' ><a href='javascript:void(0);'>«</a></li><li class='next col-xs-3' ><a href='javascript:void(0);'>»</a></li></ul></li>");
				   }
				   planTitlePanel.append(htmlTitle.join(' '));
				   planInfoPanel.append(htmlInfo.join(' '));
			   }else{
				   planTitlePanel.empty();
				   planTitlePanel.append("<div>暂无数据</div>");
				   planInfoPanel.empty();
			   }
			   //点击列表的第一个
               $(".in>.panel-body .nav li:first a").click();
    	   }else{
    		   layer.alert(data.msg);
    	   }
       }).error(function(){
    	   layer.alert("网络异常,请刷新页面再试");
       });
});
//分页加载更多
//上一页
$('section').on('click','.plan-pager .previous:not(.disabled)', function() {
	var projectId=$(".in").attr("id").substr(12);
	var planTitlePanel=$(".in").find(".plans-panel>.col-xs-2>ul");
	var planInfoPanel=$(".in").find(".plans-panel>.col-xs-10.tab-content");
	planTitlePanel.empty();
	planTitlePanel.append("<i class='icon icon-spin icon-spinner-indicator'></i>");
	planInfoPanel.empty();
	planInfoPanel.append("<div>等待左侧加载.....</div>");
	var numberOld=$("#plan-num").val();
	var number=Number(numberOld)-Number(13);
    $.post(path+'/report/project/plan/title/'+number+'?t='+new Date().getTime(),{"projectId":projectId},function(data){
 	   if(data.state){
 		  $("#plan-num").val(number);
		   //清除元素 保证页面显示正确
 		   planTitlePanel.empty();
 		   planInfoPanel.empty();
 		   var htmlTitle = [];
 		   var htmlInfo = [];
			   var planList=data.list;
			   if(planList!==null){
					for(var i = 0; i < planList.length; i++){
						htmlTitle.push("<li class='text-font-two'><a href='javascript:void(0);' data-target='#plan-"+planList[i].id+"' data-toggle='tab'>计划编码&nbsp;:&nbsp;"+planList[i].planCode+"</a></li>");
						htmlInfo.push("<div class='tab-pane fade' id='plan-"+planList[i].id+"'><div class='panel plan-item'><div class='panel-body'></div></div>" +
								"<div class='panel table-responsive  scrollbar-hover table-scroll'><table class='table table-condensed'><tr class='th_data' ><th>物料编码</th><th>物料名称</th><th>长(cm)</th><th>宽(cm)</th><th>高(cm)</th><th>体积(m³)</th><th>净重(kg)</th><th>所在容器</th><th width='22%' >所在地点</th></tr></table></div></div>");
					}
				   //控制分页显示
				   if(number<=0){
					   if(planList.length>=13){
						   htmlTitle.push("<li><ul class='pager plan-pager pager-justify pager-pills col-xs-12'><li class='previous col-xs-9 disabled' ><a href='javascript:void(0);'>«</a></li><li class='next col-xs-3' ><a href='javascript:void(0);'>»</a></li></ul></li>");
					   }
				   }else{
					   htmlTitle.push("<li><ul class='pager plan-pager pager-justify pager-pills col-xs-12'><li class='previous col-xs-9' ><a href='javascript:void(0);'>«</a></li><li class='next col-xs-3 ' ><a href='javascript:void(0);'>»</a></li></ul></li>");
				   }
				   planTitlePanel.append(htmlTitle.join(' '));
				   planInfoPanel.append(htmlInfo.join(' '));
			   }else{
				   planTitlePanel.empty();
				   planTitlePanel.append("<div>数据错误,请刷新页面后再试!</div>");
				   planInfoPanel.empty();
			   }
			   //点击列表的第一个
            $(".in>.panel-body .nav li:first a").click();
 	   }else{
 		   layer.alert(data.msg);
 	   }
    }).error(function(){
 	   layer.alert("网络异常,请刷新页面再试");
    });
});
//下一页
$('section').on('click','.plan-pager .next:not(.disabled)', function() {
	var projectId=$(".in").attr("id").substr(12);
	var planTitlePanel=$(".in").find(".plans-panel>.col-xs-2>ul");
	var planInfoPanel=$(".in").find(".plans-panel>.col-xs-10.tab-content");
	planTitlePanel.empty();
	planTitlePanel.append("<i class='icon icon-spin icon-spinner-indicator'></i>");
	planInfoPanel.empty();
	planInfoPanel.append("<div>等待左侧加载.....</div>");
	var numberOld=$("#plan-num").val();
	var number=Number(numberOld)+Number(13);
    $.post(path+'/report/project/plan/title/'+number+'?t='+new Date().getTime(),{"projectId":projectId},function(data){
 	   if(data.state){
 		  $("#plan-num").val(number);
		   //清除元素 保证页面显示正确
 		   planTitlePanel.empty();
 		   planInfoPanel.empty();
 		   var htmlTitle = [];
 		   var htmlInfo = [];
			   var planList=data.list;
			   if(planList!==null){
					for(var i = 0; i < planList.length; i++){
						htmlTitle.push("<li class='text-font-two'><a href='javascript:void(0);' data-target='#plan-"+planList[i].id+"' data-toggle='tab'>计划编码&nbsp;:&nbsp;"+planList[i].planCode+"</a></li>");
						htmlInfo.push("<div class='tab-pane fade' id='plan-"+planList[i].id+"'><div class='panel plan-item'><div class='panel-body'></div></div>" +
								"<div class='panel table-responsive  scrollbar-hover table-scroll'><table class='table table-condensed'><tr class='th_data' ><th>物料编码</th><th>物料名称</th><th>长(cm)</th><th>宽(cm)</th><th>高(cm)</th><th>体积(m³)</th><th>净重(kg)</th><th>所在容器</th><th width='22%' >所在地点</th></tr></table></div></div>");
					}
				   //控制分页显示
				   if(planList.length>=13){
					   htmlTitle.push("<li><ul class='pager plan-pager pager-justify pager-pills col-xs-12'><li class='previous col-xs-9' ><a href='javascript:void(0);'>«</a></li><li class='next col-xs-3' ><a href='javascript:void(0);'>»</a></li></ul></li>");
				   }else{
					   htmlTitle.push("<li><ul class='pager plan-pager pager-justify pager-pills col-xs-12'><li class='previous col-xs-9' ><a href='javascript:void(0);'>«</a></li><li class='next col-xs-3 disabled' ><a href='javascript:void(0);'>»</a></li></ul></li>");
				   }
				   planTitlePanel.append(htmlTitle.join(' '));
				   planInfoPanel.append(htmlInfo.join(' '));
			   }else{
				   planTitlePanel.empty();
				   planTitlePanel.append("<li class='text-font-two'>暂无更多数据</li><li><ul class='pager plan-pager pager-justify pager-pills col-xs-12'><li class='previous col-xs-9' ><a href='javascript:void(0);'>«</a></li><li class='next col-xs-3 disabled' ><a href='javascript:void(0);'>»</a></li></ul></li>");
				   planInfoPanel.empty();
			   }
			   //点击列表的第一个
            $(".in>.panel-body .nav li:first a").click();
 	   }else{
 		   layer.alert(data.msg);
 	   }
    }).error(function(){
 	   layer.alert("网络异常,请刷新页面再试");
    });
});


//加载计划详细信息
//加载提示
$('section').on('show.zui.tab',"a", function () {
	var planId=$(this).attr("data-target").substr(6);
    var planInfoPanel=$("#plan-"+planId).find(".panel-body");
    var planInfoTable=$("#plan-"+planId).find("tbody");
    planInfoPanel.append("<i class='icon icon-spin icon-spinner-indicator'></i>");
    planInfoTable.append("<tr class='not_data'><td colspan='9'><i class='icon icon-spin icon-spinner-indicator'></i></td></tr>");
});

$('section').on('shown.zui.tab',"a", function () {
	var planId=$(this).attr("data-target").substr(6);
    var planInfoPanel=$("#plan-"+planId).find(".panel-body");
    var planInfoTable=$("#plan-"+planId).find("tbody");
    //计划信息
    $.post(path+'/report/project/plan/info/'+planId+'?t='+new Date().getTime(),function(data){
	   if(data.state){
		   //清除元素 保证页面显示正确
		   planInfoPanel.empty();
	       var htmlhead = "";
	       var htmlfoot = "";
		   var planInfo=data.obj;
		   if(planInfo!=null){
		        statusHtml="<span class='text-font-two col-xs-2'>状态&nbsp;:&nbsp;<i class='icon icon-question-sign'></i>未知</span>";
				// 0当前任务1未来任务2已完成3延期未完成4未完成已异常通知
				if(planInfo.status==0){
					statusHtml="<span class='text-font-two col-xs-2'>状态&nbsp;:&nbsp;<i class='icon icon-forward'></i>正在进行中</span>";
				}else if(planInfo.status==1){
					statusHtml="<span class='text-font-two col-xs-2'>状态&nbsp;:&nbsp;<i class='icon icon-ban-circle'></i>不在进行中</span>";
				}else if(planInfo.status==2){
					statusHtml="<span class='text-font-two col-xs-2'>状态&nbsp;:&nbsp;<i class='icon icon-check-circle-o'></i>已经完成</span>";
				}else if(planInfo.status==3){
					statusHtml="<span class='text-font-two col-xs-2'>状态&nbsp;:&nbsp;<i class='icon icon-forward'></i>已延期</span>";
				}else if(planInfo.status==4){
					statusHtml="<span class='text-font-two col-xs-2'>状态&nbsp;:&nbsp;<i class='icon icon-exclamation-sign'></i>出现异常</span>";
				}
				var  entryHtmlException = "<div class='row plan-info'><span class='col-xs-10'>计划执行情况&nbsp;:&nbsp;</span></div>"
					if(planInfo.hasException==1){
				    	   entryHtmlException = "<div class='row plan-info'><span class='col-xs-10'>计划执行情况&nbsp;:&nbsp;</span><a href='javascript:void(0);' class='view-exception col-xs-2' data-id='"+planInfo.planId+"'>查看异常</a></div>" 
                    }
				var entryHtml=[];
				var planEntry=planInfo.planEntry;
				if(planEntry!=null){
					for (var x = 0; x < planEntry.length; x++) {
					     var entryHtmlChildBegin="";
					     var entryHtmlChildOver="";
						   if(x!=planEntry.length-1){
                               if(planEntry[x].states==1){ 
                            	   if(planEntry[x].arrive==2){
                            		   entryHtmlChildBegin = "<span data-id='"+planEntry[x].id+"' class='item-city item-city-error'>"+planEntry[x].addressName+"</span><span data-id='"+planEntry[x].id+"'  class='item-line item-line-error'>→<i class='icon icon-dot-circle'></i>→</span>";
                            	   }else if(planEntry[x].arrive==1){
                            		   entryHtmlChildBegin = "<span data-id='"+planEntry[x].id+"' class='item-city item-city-error'>"+planEntry[x].addressName+"</span><span data-id='"+planEntry[x].id+"'  class='item-line'>→<i class='icon icon-dot-circle'></i>→</span>";
                            	   }else{
                            		   entryHtmlChildBegin = "<span data-id='"+planEntry[x].id+"' class='item-city '>"+planEntry[x].addressName+"</span><span data-id='"+planEntry[x].id+"'  class='item-line'>→<i class='icon icon-dot-circle'></i>→</span>";
                            	   }
                               }else{   
                            	   if(planEntry[x].arrive==2){
                            		   entryHtmlChildBegin = "<span data-id='"+planEntry[x].id+"' class='item-city item-city-arrive'>"+planEntry[x].addressName+"</span><span data-id='"+planEntry[x].id+"'  class='item-line item-line-arrive'>→<i class='icon icon-dot-circle'></i>→</span>";
                            	   }else if(planEntry[x].arrive==1){
                            		   entryHtmlChildBegin = "<span data-id='"+planEntry[x].id+"' class='item-city item-city-arrive'>"+planEntry[x].addressName+"</span><span data-id='"+planEntry[x].id+"'  class='item-line'>→<i class='icon icon-dot-circle'></i>→</span>";
                            	   }else{
                            		   entryHtmlChildBegin = "<span data-id='"+planEntry[x].id+"' class='item-city '>"+planEntry[x].addressName+"</span><span data-id='"+planEntry[x].id+"'  class='item-line'>→<i class='icon icon-dot-circle'></i>→</span>";
                            	   }
                               }    
                         }else{
                         if(planEntry[x].states==1){ 
                        	 if(planEntry[x].arrive!=0){
                        		 entryHtmlChildOver= "<span data-id='"+planEntry[x].id+"'  class='item-city item-city-error'>"+planEntry[x].addressName+"</span>";
                        	 }else{
                        		 entryHtmlChildOver= "<span data-id='"+planEntry[x].id+"'  class='item-city '>"+planEntry[x].addressName+"</span>";
                        	 }
                          }else{
                        	  if(planEntry[x].arrive!=0){
                         		 entryHtmlChildOver= "<span data-id='"+planEntry[x].id+"'  class='item-city item-city-arrive'>"+planEntry[x].addressName+"</span>";
                         	 }else{
                         		 entryHtmlChildOver= "<span data-id='"+planEntry[x].id+"'  class='item-city '>"+planEntry[x].addressName+"</span>";
                         	 }
                          }}
						   entryHtml.push(entryHtmlChildBegin+entryHtmlChildOver);
					}
				}else{
					entryHtml.push("<span>暂无数据</span>");
				}
				var entryHtml=entryHtml.join('');
				htmlhead="<div class='row plan-info'><span class='text-font-two col-xs-10'>计划描述&nbsp;:&nbsp;"+planInfo.remark+"</span>"+statusHtml+"</div><div class='row plan-info'><span class='col-xs-4'>运输方式&nbsp;:&nbsp;"+planInfo.transportTypeName+"</span><span class='col-xs-4'>距离&nbsp;:&nbsp;"+nulltoString(planInfo.distance)+"&nbsp;km</span><span class='col-xs-4'>时间期间&nbsp;:&nbsp;<span style='color: #3280fc'>"+planInfo.startDateStr+"</span>&nbsp;至&nbsp;<span style='color: #3280fc'>"+planInfo.endDateStr+"</span></span></div>"
				htmlfoot="<div class='row plan-info'><span class='col-xs-8'>起始地&nbsp;:&nbsp;"+nulltoString(planInfo.startPlaceName)+"&nbsp;&nbsp;&nbsp;&nbsp;目的地&nbsp;:&nbsp;"+nulltoString(planInfo.destinationName)+"</span><span class='col-xs-4'>创建时间&nbsp;:&nbsp;<span style='color: #0350c9'>"+planInfo.createTimeStr+"</span></span></div>"+entryHtmlException+"" +
						"<div class='col-xs-12 plan-info'>"+entryHtml+"</div><div class='row'><span class='col-xs-3'>周末&nbsp;:&nbsp;2&nbsp;天</span><span class='col-xs-3'>假期政策&nbsp;:&nbsp;7&nbsp;天</span><span class='col-xs-6'>引用模版&nbsp;:&nbsp;"+planInfo.templateName+"</span></div>";
				planInfoPanel.append(htmlhead+htmlfoot);
				/*//点击列表的第一个
			    var arrives=$(".in .active .panel-body .item-city:first");
			    if(arrives.hasClass("item-city-arrive")||arrives.hasClass("item-city-error")){
			    	arrives.click();
			    }else{
			    	$(".not_data").remove();
			  		$(".td_data").remove();
					planInfoTable.append("<tr class='not_data'><td colspan='9' align='center'>计划未执行暂无数据</td></tr>");
			    }*/
				$($(".in .active .panel-body .col-xs-12.plan-info span").toArray().reverse()).each(function (i){ 
					  if($(this).hasClass("item-city-arrive")||$(this).hasClass("item-city-error")||$(this).hasClass("item-line-arrive")||$(this).hasClass("item-line-error")){  
						  $(this).click();
						  return false; //跳出循环
					  }else{
						  if(i==$(".in .active .panel-body .col-xs-12.plan-info span").length-1){
				    			$(".not_data").remove();
						  		$(".td_data").remove();
								planInfoTable.append("<tr class='not_data'><td colspan='9' align='center'>计划未执行暂无数据</td></tr>");
								return false; //跳出循环
				    		}
					  }
				});
		   }else{
			   layer.alert("数据错误,请刷新页面后再试");
		   }
	   }else{
 		   layer.alert(data.msg);
 	   }
    }).error(function(){
 	   layer.alert("网络异常,请刷新页面再试");
    });
});
//计划途经地被点击---获取物料信息
$('section').on('click','.item-city-error, .item-city-arrive', function() {
	 $("#materiel-num").val(0);
	//控制选中的样式
	$(".chose-city").removeClass("chose-city");
	$(".chose-line").removeClass("chose-line");
	$(this).addClass("chose-city");
	getMaterielInfoByType(0);
});

//计划途经地之间被点击---获取物料信息
$('section').on('click','.item-line-error, .item-line-arrive', function() {
	 $("#materiel-num").val(0);
	//控制选中的样式
	$(".chose-city").removeClass("chose-city");
	$(".chose-line").removeClass("chose-line");
	$(this).addClass("chose-line");
	getMaterielInfoByType(1);
});

//查询物料信息
function getMaterielInfoByType(type){
	var planEntryId=$("span[class*='chose-']").attr("data-id");
	var planId=$(".panel-collapse.in ul .active a").attr("data-target").substr(6);
	var planInfoTable=$("#plan-"+planId).find("tbody");
	   $.post(path+'/report/project/plan/materiel/0?t='+new Date().getTime(),{"planEntryId":planEntryId,"type":type},function(data){
	  	   if(data.state){
	 		   //清除元素 保证页面显示正确
	  		   $(".td_data").remove();
	  		   $(".not_data").remove();
		       var html = [];
			   var materiel=data.list;
			   if(materiel!=null){
					for(var i = 0; i < materiel.length; i++){
							html.push("<tr class='td_data'><td>"+materiel[i].materielCode+"</td><td>"+materiel[i].materielName+"</td><td>"+materiel[i].length+"</td><td>"+materiel[i].width+"</td><td>"+materiel[i].height+"</td><td>"+(materiel[i].volume)/1000000+"</td><td>"+materiel[i].emptyWeight+"</td><td>"+materiel[i].beContainerName+"</td><td>"+materiel[i].beAddressName+"</td></tr>");
					}
					if(materiel.length>=20){
						html.push("<tr class='not_data'><td colspan='9' align='center'><button id='materielLoading' type='button' class='btn btn-block loadingBtn' data-loading-text='正在加载中...'>点击加载更多</button></td></tr>");
					}
					planInfoTable.append(html.join(' '));
			   }else{
				   $(".not_data").remove();
				   $(".td_data").remove();
				   planInfoTable.append("<tr class='not_data'><td colspan='9' align='center'>暂无数据</td></tr>");
			   }
	  	   }else{
	  		   layer.alert(data.msg);
	  	   }
	     }).error(function(){
	  	   layer.alert("网络异常,请刷新页面再试");
	     });
}


//物料信息 加载更多
$('section').on('click','#materielLoading', function() {
	var $btn = $(this);
	$btn.button('loading');
	var infos=$("span[class*='chose-']");
	if(infos.hasClass("chose-city")){
		var type=0;
	}else if(infos.hasClass("chose-line")){
		var type=1;
	}
	var planEntryId=infos.attr("data-id");
	var planId=$(".panel-collapse.in ul .active a").attr("data-target").substr(6);
	var planInfoTable=$("#plan-"+planId).find("tbody");
	var numberOld=$("#materiel-num").val();
	var number=Number(numberOld)+Number(20);
    $.post(path+'/report/project/plan/materiel/'+number+'?t='+new Date().getTime(),{"planEntryId":planEntryId,"type":type},function(data){
   	   if(data.state){
   		  $("#materiel-num").val(number);
  		   //清除元素 保证页面显示正确
   		   $(".not_data").remove();
   		   var html = [];
		   var materiel=data.list;
		   if(materiel!==null){
				for(var i = 0; i < materiel.length; i++){
						html.push("<tr class='td_data'><td>"+materiel[i].materielCode+"</td><td>"+materiel[i].materielName+"</td><td>"+materiel[i].length+"</td><td>"+materiel[i].width+"</td><td>"+materiel[i].height+"</td><td>"+(materiel[i].volume)/1000000+"</td><td>"+materiel[i].emptyWeight+"</td><td>"+materiel[i].beContainerName+"</td><td>"+materiel[i].beAddressName+"</td></tr>");
				}
				if(materiel.length>=20){
					html.push("<tr class='not_data'><td colspan='9' align='center'><button id='materielLoading' type='button' class='btn btn-block loadingBtn' data-loading-text='正在加载中...'>点击加载更多</button></td></tr>");
				}
 				planInfoTable.append(html.join(' '));
 		   }else{
 			   $(".not_data").remove();
 			   planInfoTable.append("<tr class='not_data'><td colspan='9' align='center'>暂无更多数据</td></tr>");
 		   }
   	   }else{
   		   layer.alert(data.msg);
   		   $btn.button('reset');
   	   }
      }).error(function(){
   	   layer.alert("网络异常,请刷新页面再试");
       $btn.button('reset');
      });
});

//点击查看异常
$('section').on('click','.view-exception', function() {
	$("#EXmodal .modal-body").empty();
	var planId = $(this).attr("data-id");
	$.post(path+'/report/project/plan/exception/'+planId+'?t='+new Date().getTime(),function(data){
		if(data.state){
			$("#EXmodal").modal({show : true});
			var list=data.data;
			for ( var i in list) {
				$("#EXmodal .modal-body").append("<div class='col-xs-12'>"+list[i]+"</div>");
			}
		}else{
			layer.alert(data.msg);
		}
	}).error(function(){
		 layer.alert("网络异常,请刷新页面再试");
	});
});
